package com.example.controller;

import com.example.common.Result;
import com.example.entity.College;
import com.example.service.CollegeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/college")
public class CollegeController {
    @Autowired
    private CollegeService collegeService;

    /**
     * 添加
     */
    @PostMapping("/add")
    public Result add(@RequestBody College college) {
        collegeService.add(college);
        return Result.success();
    }

    /**
     * 分页和条件查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam (defaultValue = "5") Integer pageSize, String name) {
        PageInfo<College> pageInfo = collegeService.selectPage(pageNum,  pageSize, name);
        return Result.success(pageInfo);

    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(College college) {
        List<College> list = collegeService.selectAll(college);
        return Result.success(list);
    }

    /**
     * 更新
     */
    @PutMapping("/update")
    public Result update(@RequestBody College college) {
        collegeService.update(college);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        collegeService.deleteById(id);
        return Result.success();
    }


}
